<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <ul>
      <li v-for="item in cities" v-if="item.name !=='北京'" >
        <input type="text" v-model="item.num">
        {{item.num}} {{item.name}}
      </li>
    </ul>
    <hr>
    {{total}}
  </div>

  <script>
    var cities = [{ name: '太原', num: 800 }, { name: "北京", num: 2400 }, { name: "上海", num: 1800 }]
    new Vue({
      el: "#app",
      data: {
        cities
      },
      created() {
        fetch("http://127.0.0.1:3001/api/cities").then((res) => res.json()).then((res) => {
          this.cities = res;
        })
      },
      computed: {
        total() {
          return this.cities.reduce((count, cur) => {
            count += parseInt(cur.num);
            return count;
          }, 0)
        }
      }
    })
  </script>

</body>

</html>